import request from '@/plugins/request'
import { IResponseData } from '@/types/request-base'
import { json2FormData } from '@/utils'
// 经销商联系人/门店联系人

/**
 * 查询变更单联系人
 * @param {String} changeId  变更单ID
 * @param {String} shopCode 门店编码
 */
export function getCustomerContact(changeId: string, shopCode?: String) {
  let url = `/app/v1/ctmCustomerContact?changeId=${changeId}`
  if (shopCode) {
    url += `&shopCode=${shopCode}`
  }
  return request<IResponseData>({
    method: 'get',
    url,
    loading: true
  })
}

/**
 * 查询变更单联系人原始数据(来自MDM)
 * @param {String} changeId  变更单ID
 * @param {String} shopCode 门店编码
 */
export function getMdmCustomerContact(changeId: string, shopCode?: String) {
  let url = `/app/v1/ctmCustomerContact/mdm/contact?changeId=${changeId}`
  if (shopCode) {
    url += `&shopCode=${shopCode}`
  }
  return request<IResponseData>({
    method: 'get',
    url
  })
}

/**
 * 保存联系人
 * @param {Number} contactScope 范围：1 经销商联系人， 3 门店联系人
 * @param {String} changeCode 变更单编码
 * @param {Array} data 列表数据
 */
export function saveContacts(contactScope: Number, changeCode: string, data: any) {
  return request<IResponseData>({
    method: 'post',
    url: `/app/v1/ctmCustomerChange/insertOrUpdate/${
      contactScope === 3 ? 'shopContact' : 'infoContact'
    }?changeCode=${changeCode}`,
    data,
    loading: true,
    headers: {
      repeatSubmit: false
    }
  })
}

/**
 * 新增门店联系人查找
 * @param {String} changeId  变更单ID
 */
export function getNewShopContact(changeId: string) {
  const url = `/app/v1/ctmCustomerContact/shop/contact?changeId=${changeId}`
  return request<IResponseData>({
    method: 'get',
    url,
    loading: true
  })
}
